package com.qf.flowerlanguage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.flowerlanguage.entity.Classes;
import com.qf.flowerlanguage.service.ClassesService;
import com.qf.flowerlanguage.vo.ClassesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/classes")
public class ClassesController {
    @Autowired
    private ClassesService classesService;

    @RequestMapping("/selectProductAndClasses")
    @ResponseBody
    public ClassesVo selectProductAndClasses(Classes classes){
        QueryWrapper<Classes> homeQW = new QueryWrapper<>();
//        String cway1 = classes.getCway();
//        String[] split = cway1.split(",");//'12','35'
//        StringBuilder stringBuilder=new StringBuilder();
//        for (String s :split) {
//            stringBuilder.append("'"+s+"'"+",");
//        }
//
//        String string = stringBuilder.toString();
//        System.out.println(string);
        String cway1 = classes.getCway();
        String[] split = cway1.split(",");
        QueryWrapper<Classes> cway = homeQW.in("cway", split);
        List<Classes> list = classesService.list(cway);
        ClassesVo classesVo=new ClassesVo();
        if (list.size()==0){
            classesVo.setCode("1");
            classesVo.setMessage("无可用字段");
        }else {
            classesVo.setCode("0");
            classesVo.setMessage("字段有效");
            classesVo.setClasses(list);
        }
        return classesVo;


    }
}
